package com.y.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.y.config.exception.AccountLoginException;
import com.y.entity.Food;
import com.y.entity.vo.DataTable;
import com.y.entity.vo.RHttpStatusEnum;
import com.y.service.FoodService;
import com.y.utils.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 前端页面控制器
 * @author: Yjh
 */
@Controller
@RequestMapping("/front")
public class FrontController {

    @Resource
    FoodService foodService;


    @RequestMapping("/index")
    public String index(Model model){

        return "front/index";
    }

    @GetMapping("/toOrder")
    public String toAdopt(Model model){
        // 正在售卖 数量大于0
        List<Food> data = foodService.list(new QueryWrapper<Food>().eq("status","0").gt("nums","0"));
        model.addAttribute("foods",data);
        return "front/order";

    }

    @GetMapping("/addCart/{id}")
    public String addCart(@PathVariable(value = "id") Integer id,Model model){
        Assert.isTrue(StpUtil.isLogin(),new AccountLoginException(RHttpStatusEnum.USER_NOT_LOGIN));
        model.addAttribute("food",foodService.getById(id));
        return "front/addCart";

    }


}
